package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.Shiwu;
import com.ruoyi.system.mapper.ShiwuMapper;
import com.ruoyi.system.service.IShiwuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZhuanjiaBiandongPiciMapper;
import com.ruoyi.system.domain.ZhuanjiaBiandongPici;
import com.ruoyi.system.service.IZhuanjiaBiandongPiciService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 专家变动批次Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Service
public class ZhuanjiaBiandongPiciServiceImpl implements IZhuanjiaBiandongPiciService 
{
    @Autowired
    private ZhuanjiaBiandongPiciMapper zhuanjiaBiandongPiciMapper;

    @Autowired
    private ShiwuMapper shiwuMapper;

    /**
     * 查询专家变动批次
     * 
     * @param id 专家变动批次主键
     * @return 专家变动批次
     */
    @Override
    public ZhuanjiaBiandongPici selectZhuanjiaBiandongPiciById(String id)
    {
        return zhuanjiaBiandongPiciMapper.selectZhuanjiaBiandongPiciById(id);
    }

    /**
     * 查询专家变动批次列表
     * 
     * @param zhuanjiaBiandongPici 专家变动批次
     * @return 专家变动批次
     */
    @Override
    public List<ZhuanjiaBiandongPici> selectZhuanjiaBiandongPiciList(ZhuanjiaBiandongPici zhuanjiaBiandongPici)
    {
        return zhuanjiaBiandongPiciMapper.selectZhuanjiaBiandongPiciList(zhuanjiaBiandongPici);
    }

    /**
     * 新增专家变动批次
     * 
     * @param zhuanjiaBiandongPici 专家变动批次
     * @return 结果
     */
    @Override
    public int insertZhuanjiaBiandongPici(ZhuanjiaBiandongPici zhuanjiaBiandongPici)
    {
        return zhuanjiaBiandongPiciMapper.insertZhuanjiaBiandongPici(zhuanjiaBiandongPici);
    }

    /**
     * 修改专家变动批次
     * 
     * @param zhuanjiaBiandongPici 专家变动批次
     * @return 结果
     */
    @Override
    public int updateZhuanjiaBiandongPici(ZhuanjiaBiandongPici zhuanjiaBiandongPici)
    {
        return zhuanjiaBiandongPiciMapper.updateZhuanjiaBiandongPici(zhuanjiaBiandongPici);
    }

    /**
     * 批量删除专家变动批次
     * 
     * @param ids 需要删除的专家变动批次主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaBiandongPiciByIds(String ids)
    {
        return zhuanjiaBiandongPiciMapper.deleteZhuanjiaBiandongPiciByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除专家变动批次信息
     * 
     * @param id 专家变动批次主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaBiandongPiciById(String id)
    {
        return zhuanjiaBiandongPiciMapper.deleteZhuanjiaBiandongPiciById(id);
    }

    @Override
    public List<Map<String,Object>> findCustomList(String ppDeptId,String ppPicimingcheng){
        ppPicimingcheng = "%"+ppPicimingcheng+"%";
        return zhuanjiaBiandongPiciMapper.findCustomList(ppDeptId,ppPicimingcheng);
    }

    @Override
    @Transactional
    public boolean addZhuanjiabiandongpiciAndShiwu(ZhuanjiaBiandongPici zhuanjiaBiandongPici,Shiwu ppShiwu){

        boolean ok = true;
        
        int addZhuanjiabiandongpici = insertZhuanjiaBiandongPici(zhuanjiaBiandongPici);

        if (addZhuanjiabiandongpici!=1){
            ok = false;
            throw new RuntimeException("添加专家变动批次失败");
        }

        int addShiwu = shiwuMapper.insertShiwu(ppShiwu);

        if (addShiwu!=1){
            ok = false;
            throw new RuntimeException("添加事务失败");
        }

        return ok;
    }
}
